<template>
    <div class="resCommon">
        <div class="search">
            <div class="classify">
                <el-radio-group v-model="activeName" @change="handleClick">
                    <el-radio-button label="public">公共</el-radio-button>
                    <el-radio-button label="tenant">租户</el-radio-button>
                </el-radio-group>
            </div>
            <div class="searchBox">
                <el-button class="addResBtn" :disabled="!(activeName=='public'&&clickStep==1)" type="primary" @click="addResBtn">新建资源</el-button>
                <search placeholder="请输入搜索内容" :live-search="true" :search-word.sync="searchName" @search="searchCon"/>
            </div>
        </div>
        <!-- 目录面包屑 -->
        <el-breadcrumb separator="/" class="breadcrumb-wrap">
            <el-breadcrumb-item></el-breadcrumb-item>
            <el-breadcrumb-item 
                v-for="(item, index) in breadcrumbList"
                :key="item.id"
                @click.native="onClickBread(item, index)"
            >
                <span class="cursor">{{item.name}}</span>
            </el-breadcrumb-item>
            <el-breadcrumb-item></el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 表格 -->
        <div class="table">
            <el-table v-loading="loading" v-show="clickStep==1" :data="resourcePublic" stripe style="width: 100%">
                <el-table-column label="目录">
                    <template slot-scope="scope">
                        <el-button @click="menuDetail(scope.row)" type="text">{{urlHandle(scope.row.url)}}</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="容量配额上限">
                    <template slot-scope="scope">
                        <span>{{scope.row.capacity}} {{scope.row.unit==1?'MB':scope.row.unit==2?"GB":scope.row.unit==3?'TB':''}}</span>
                    </template>
                </el-table-column> 
                <el-table-column label="文件配额(个)">
                    <template slot-scope="scope">
                        <span>{{scope.row.fileNum}}</span>
                    </template>
                </el-table-column>
                <el-table-column v-if="activeName=='public'" prop="tenantList" label="分配的租户">
                    <template slot-scope="scope">
                        <span v-for="(item,index) in scope.row.tenantList" :key="index">
                            {{item}}
                            <span v-if="index!=scope.row.tenantList.length-1">,</span>
                        </span>
                    </template>
                </el-table-column>
                <el-table-column v-if="activeName=='tenant'" prop="tenantList" label="所属租户">
                    <template slot-scope="scope">
                        <span>{{scope.row.owner}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-tooltip content="编辑" placement="top">
                            <el-button type="text" @click="editResource(scope.row)">
                                <i class="el-icon-edit icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="分配租户" placement="top">
                            <el-button v-if="activeName=='public'" type="text" @click="tenantBtn(scope.row)" >
                                <i class="el-icon-files icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="详情" placement="top">
                            <el-button v-if="activeName=='public'" type="text" @click="resDetail(scope.row)">
                                <i class="el-icon-view icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <el-tooltip content="删除" placement="top">
                            <el-button type="text" @click="deleteBtn(scope.row)">
                                <i class="el-icon-delete icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <el-table v-loading="loading" v-show="clickStep!=1" :data="resourcePublic" stripe style="width: 100%">
                <el-table-column label="目录">
                    <template slot-scope="scope">
                        <el-button @click="menuDetail(scope.row)" type="text">{{urlHandle(scope.row.url)}}</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="creator" label="创建者"></el-table-column>
                <el-table-column prop="updDate" label="修改时间"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-tooltip content="详情" placement="top">
                            <el-button type="text" @click="resDetail(scope.row)">
                                <i class="el-icon-view icon-fs"></i>
                            </el-button>
                        </el-tooltip>
                        <!-- <el-tooltip content="删除" placement="top">
                            <el-button v-if="activeName=='public'" type="text" @click="deleteBtn(scope.row)">
                                <i class="el-icon-delete icon-fs"></i>
                            </el-button>
                        </el-tooltip> -->
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页(默认 10条/页) -->
        <pagenation :pageInfo='pageinfo'></pagenation>
        <dialogCom :diaData='dialogData'></dialogCom>
    </div>
</template>

<script>
import DialogCom from '@/components/resource/Resource'
import Pagenation from '@/components/resource/Pagenation'
import resource from '@/mixins/resource'
import Search from '@/components/common/Search'
    export default {
        components:{ DialogCom, Pagenation, Search },
        mixins:[resource],
        data() {
            return {
                pageinfo: {
                    tenantNum: 0,
                    currentPage: 1
                },
                dialogData:{
                    type: 'HDFS',
                    label:'目录名',
                    addResourceTab: false,
                    titleTips: '',
                    opeBtn: '',
                    isDisabled: false,
                    operatorTips: '',
                    resOperate: false,
                    editData:{},
                    isPublic: ''
                },
                breadcrumbList: [
                    {
                        name: 'public',
                        id: '0'
                    }
                ],
                newResRules: {
                    name: [
                        { required: true, message: '请输入活动名称', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ]
                },
                clickStep: 1,
                isAdd: true,
                currentPage:1
            }
        },
        mounted(){
            // 获取列表
            this.getResourceList();
        },
        methods:{
            handleClicktest(){
                this.currentPage = 1;
                this.handleClick();
            },
            // 添加资源
            addResBtn(){
                let resource = this.breadcrumbList;
                let resourceId = resource[resource.length-1].id;
                this.dialogData.titleTips = '新建公共资源';
                this.dialogData.addResourceTab = true;
                this.dialogData.isDisabled = false;
                this.dialogData.editData = {};
                this.dialogData.editData.resourceId = resourceId;
                this.dialogData.parentId = resourceId;
                this.dialogData.isPublic = '1';  //1为公共资源
            },
            // 编辑
            editResource(row){
                let resource = this.breadcrumbList;
                let resourceId = resource[resource.length-1].id;
                this.dialogData.editData = row;
                if(this.activeName == 'public'){
                    this.dialogData.titleTips = '编辑公共资源';
                    this.dialogData.isPublic = '1';  //1为公共资源
                } else {
                    this.dialogData.titleTips = '编辑租户资源';
                    this.dialogData.isPublic = '0';  //1为公共资源
                }
                this.dialogData.parentId = resourceId;
                this.dialogData.addResourceTab = true;
                this.dialogData.isDisabled = true;
            }, 
        }
    }
</script>

<style lang="scss" scoped>
@import '~@/styles/resCommon.scss'
</style>